package com.tbit.uqbike.client.controller;

import com.tbit.uqbike.client.exception.BaseException;
import com.tbit.uqbike.client.pojo.Result;
import com.tbit.uqbike.client.pojo.RideLogDetails;
import com.tbit.uqbike.client.pojo.User;
import com.tbit.uqbike.client.service.RideLogDetailsService;
import com.tbit.uqbike.client.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 骑行订单详情
 *
 * @Author:BUGTian
 * @DATE: 2023/5/22
 */
@RequestMapping("/rideLogDetails")
@RestController
public class RideLogDetailsController {

    @Autowired
    private RideLogDetailsService rideLogDetailsService;
    @Autowired
    private TokenService tokenService;

    /**
     * 根据订单编号获取骑行订单详情
     *
     * @param orderNO
     * @return
     */
    @GetMapping("/queryByOrderNO")
    public Result<RideLogDetails> queryByOrderId(@NotNull String orderNO) {
        return rideLogDetailsService.queryByOrderId(orderNO);
    }

    /**
     * 查询用户的骑行订单列表
     *
     * @param token
     * @return
     */
    @GetMapping("/list")
    public Result<List<RideLogDetails>> list(@NotNull String token) {
        User user = tokenService.getUser(token);
        if (user == null) {
            throw new BaseException("-20005", "用户不存在");
        }
        return rideLogDetailsService.list(user.getUserId());
    }

}
